<template>
  <div>
    <el-card shadow="always">
      <el-divider content-position="left"><span style="font-size: 18px;">发货基本信息 [数据参考对照]
       <el-button @click="Colese()" size="mini" type="primary" style="margin-left: 35px">关闭</el-button>
      </span></el-divider>

      <el-form ref="form" :model="form" label-width="160px">
        <el-row>
          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                  申请发货日期：
                  <el-tooltip placement="right">
                    <div slot="content">
                      申请发货日期
                    </div>
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                </span>
              <el-input v-model="form.SAN_Time" readonly placeholder="申请发货日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
                <span slot="label">
                  企业名称：
                </span>
              <el-input v-model="form.SAN_CoName" readonly placeholder=" 企业名称"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                    发货人：
                  </span>
              <el-input v-model="form.SAN_Sender_Name" readonly placeholder=" 发货人"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                    收件人：
                  </span>
              <el-input v-model="form.SAN_Recipient_Name" readonly placeholder=" 收件人"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
                  <span slot="label">
                      收件人电话：
                    </span>
              <el-input v-model="form.SAN_Recipient_Tel" readonly placeholder="收件人电话"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item>
                  <span slot="label">
                      收件地址：
                      <el-tooltip placement="right">
                        <div slot="content">
                          收件地址
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-input v-model="form.SAN_Recipient_Address" readonly  placeholder=" 收件地址"/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-divider content-position="left"><span style="font-size: 18px;">发货方式 [可选择区域]</span></el-divider>

        <el-row>
          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                  发货日期：<span class="redColor">*</span>
                  <el-tooltip placement="right">
                    <div slot="content">
                      发货日期
                    </div>
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                </span>

              <el-date-picker
                v-model="form.EIY_Ship_Time"
                placeholder="选择发货日期"
                size="small"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                :picker-options="pickerOptionsDay">
              </el-date-picker>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="4">
            <el-form-item>
                  <span slot="label">
                      发货方式：
                      <el-tooltip placement="right">
                        <div slot="content">
                          发货方式 快递、物流、送货、自取、其他
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.EIY_ShiptyID" placeholder="发货方式" @change="changeEIY_ShiptyID(null)"
                         style="width: 100%;">
                <el-option
                  v-for="dict in DeliveryMethodOption"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
                  <span slot="label" v-show="EIY_FpayType_show">
                      运费方式：
                      <el-tooltip placement="right">
                        <div slot="content">
                          运费方式 发货方式 为 快递、物流 时 需选择 运费方式 寄付 到付
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.EIY_FpayType" v-show="EIY_FpayType_show"  placeholder="运费方式" style="width: 100%;">
                <el-option
                  v-for="dict in ShippingMethodOption"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"

                />
              </el-select>

              <span slot="label" v-show="EIY_Delivery_Person_show">
                      送货人：
                      <el-tooltip placement="right">
                        <div slot="content">
                          送货人 发货方式 为 送货 时 需填写 送货人
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                </span>
              <el-input v-model="form.EIY_Delivery_Person" v-show="EIY_Delivery_Person_show" placeholder="送货人"/>
              <span slot="label" v-show="EIY_Remarks_show">
                      备注：
                      <el-tooltip placement="right">
                        <div slot="content">
                          备注 发货方式 为 自取或其他 时 需填写 备注
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-input type="textarea"  v-show="EIY_Remarks_show" v-model="form.EIY_Remarks"  placeholder="备注" max-length="100"/>
            </el-form-item>


          </el-col>
          <el-col :span="6">
            <el-form-item v-show="EIY_FpayType_show">
                  <span slot="label">
                      快递公司：
                      <el-tooltip placement="right">
                        <div slot="content">
                          快递公司 发货方式 为 快递、物流 时 需选择 快递公司
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.SAN_Express_Delivery" placeholder="快递公司" style="width: 100%;">
                <el-option
                  v-for="dict in CourierCompanyOptions"
                  :key="dict.EDY_ID"
                  :label="dict.EDY_Name"
                  :value="dict.EDY_ID"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item v-show="EIY_FpayType_show">
                  <span slot="label">
                      快递单号：
                      <el-tooltip placement="right">
                        <div slot="content">
                          快递单号 发货方式 为 快递、物流 时 需填写 快递单号
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-input v-model="form.EIY_Tracking_Number"  placeholder="快递单号" max-length="100"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider v-hasPermi="['yunze:ExpressInquiry:updSignFor']"  content-position="left"><span style="font-size: 18px;">快递状态修改 [可选择区域]</span></el-divider>
        <el-row v-hasPermi="['yunze:ExpressInquiry:updSignFor']" >
          <el-col :span="4">
            <el-form-item>
                  <span slot="label">
                      签收状态：
                      <el-tooltip placement="right">
                        <div slot="content">
                          签收状态 未收、已收、退回
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.EIY_Signing_Status" placeholder="签收状态"
                         style="width: 100%;">
                <el-option
                  v-for="dict in ExpressInquiry_SignForOption"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item>
                  <span slot="label">
                      快递评价：
                      <el-tooltip placement="right">
                        <div slot="content">
                          快递评价 未评价、正常、慢、损坏、丢件
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.EIY_Evaluation_Status" placeholder="快递评价"
                         style="width: 100%;">
                <el-option
                  v-for="dict in ExpressInquiry_EvaluationOption"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                  签收日期：<span class="redColor">*</span>
                  <el-tooltip placement="right">
                    <div slot="content">
                      签收日期
                    </div>
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                </span>

              <el-date-picker
                v-model="form.EIY_Time"
                placeholder="选择收件日期"
                size="small"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                :picker-options="pickerOptionsDay">
              </el-date-picker>
            </el-form-item>
          </el-col>


        </el-row>






        <el-collapse v-model="collapseSelIndex"  style="margin-left: 10px; margin-top: 10px;">
          <el-collapse-item name="1">
            <template slot="title" class="item_iccid">
              <div style="font-size:20px;">发货信息 [数据参考对照]</div>
            </template>
            <template>
              <el-table v-loading="loading" :data="CommodityList" >
                <el-table-column label="来源类型" align="center" prop="EIDS_Shipping_Type"/>
                <el-table-column label="名称/金额" align="center" prop="EIDS_Name"/>
                <el-table-column label="数量" property="pricing" prop="EIDS_Quantity"/>
              </el-table>
            </template>
          </el-collapse-item>
        </el-collapse>



      </el-form>

    </el-card>
    <div style="float: right; margin-right: 50px;margin-top: 50px;">
      <el-button v-if="CustomerEdie" v-hasPermi="['yunze:ExpressInquiry:upd']" type="primary" @click="Edie">保 存
      </el-button>
      <el-button  type="primary" @click="Colese()">关 闭</el-button>
    </div>



    <!-- 编辑 快递查询 触发函数-->
    <span v-if="show_ds_Register ==true && execute == false"  >
      {{SetShipmentApplication()}}
    </span>





  </div>
</template>

<script>

  import tools from "@/utils/yunze/tools";
  import { FindInfo} from "@/api/yunze/FHGL/ExpressInquiry";
  import { Commodity,} from "@/api/yunze/warehouse/Inout";
  import { getUndoneContract} from "@/api/yunze/FHGL/OrderDelivery/OrderDelivery";
  import {findCustomerArr, fnidAccountArr, fnidPeopleArr} from "@/api/yunze/XSGL/customer/customer";



  export default {
    /*获取传值
    * 官方文档
    * https://cn.vuejs.org/v2/guide/components-props.html#%E4%BC%A0%E5%85%A5%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%89%80%E6%9C%89-property
    * String Number Boolean Array Object Date Function Symbol
    * */
    props: {//参数 接受
      DeliveryMethodOption: Array, //数据字典 发货方式
      ShippingMethodOption: Array,//数据字典 运费方式
      CourierCompanyOptions: Array,//数据字典 快递公司信息
      form: Object,// 表单参数
      window:Window,//window 操作对象
      CustomerAdd: Boolean, //新增 按钮
      CustomerEdie: Boolean, //编辑 按钮
      show_ds_Register: Boolean,// 子窗体 载入显示 bool 用来控制 当前界面触发函数
      execute: Boolean,// 子窗体 载入显示 bool 用来控制 当前界面触发函数
      SubUpd: Function,//编辑 提交
      ExpressInquiry_SignForOption: Array,//数据字典 快递签收状态
      ExpressInquiry_EvaluationOption: Array,//数据字典 快递评价
    },
    data() {//数据变量定义
      return {


        EIY_Ship_Time: tools.gitData(),//发货日期

        IsLoadShooingAdd:false,// 界面是否 渲染过
        disabledDeliverySelectionType:[],//禁止选择 发货来源选择

        EditBool:false,//当前打开方式是否为 编辑
        otherList:[],//其他发货 arr
        otherList_delArr:[],//其他发货 arr 删除
        othertitle:'',//新增 发票发货 标题
        other_show:false,//新增 其他发货 显示
        addotherBtn:false,//新增按钮 其他发货 显示
        editotherBtn:false,//关闭按钮 其他发货 显示
        //其他发货 form
        otherform:{
          SAOR_Name:'',
          SAOR_ModelAndNumber:'',
          SAOR_Unit:'',
          SAOR_Quantity:'1',
        },

        InvoiceList:[],//发票发货 arr
        InvoiceList_delArr:[],//发票发货 arr 删除
        Invoicetitle:'',//新增 发票发货 标题
        Invoice_show:false,//新增 发票发货 显示
        addInvoiceBtn:false,//新增按钮 发票发货 显示
        editInvoiceBtn:false,//关闭按钮 发票发货 显示

        //发票发货 form
        Invoiceform:{
          SAIE_Billing_Company:'',
          SAIE_Quantity:'1',
        },

        SAIE_show: false,// 新增发票发货 显示
        formalDetailsArr: [],// 正式合同发货信息详情
        formalDetailsArr_delArr: [],// 正式合同发货信息详情 删除
        UndoneCodeOption:[],//未完成的 销售合同
        collapseSelIndex:['0','1','2','3'],// collapse 默认展开
        cities: [],// 复选框 数组
        cityOptions: [],//  复选框 检索临时缓存
        checkAll: false,//全选按钮 绑定值
        isIndeterminate: false,//全选按钮 是否选中
        checkedCities: [],//商品选择

        FindOption_show: false,//查询商品按钮 显示
        innerDrawer: false,//回显展示
        PeopleOption: [],//根据 查询条件加载的 客户联系人
        AccountOption: [],//根据 查询条件加载的 客户地址
        CustomerOption: [],//根据 查询条件加载的销售客户信息
        //  商品 信息 数据
        CommodityList: [], //普通发货
        CommodityList_delArr :[],// 普通发货 删除
        loading: false,// 遮罩层
        ContractDelivery_show: false,//合同发货 显示
        OrdinaryDelivery_show: false,//普通发货  显示
        InvoiceDelivery_show: false,//发票发货 显示
        OtherDelivery_show: false,//其他发货 显示

        //日期时间选择
        pickerOptionsDay: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', tools.gitData());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              picker.$emit('pick', tools.getBeforeDate(1));
            }
          }, {
            text: '一周前',
            onClick(picker) {
              picker.$emit('pick', tools.getBeforeDate(7));
            }
          }]
        },
        //当前查询参数
        Sel: {
          gradeIdArr: [],
          oneIdArr: [],
          TowIdArr: [],
          sourceIdArr: [],
          province: null,
          city: null,
          district: null,
          c_name: null,
        },
        EIY_FpayType_show: true,//运费方式 显示
        EIY_Delivery_Person_show: false,//送货人 显示
        EIY_Remarks_show: false,//备注 显示

        tools:tools,//tools 工具类


        // 查询参数
        queryParams: {},
      };
    },
    mounted() {//全部渲染完成后自动引函数 【作为子组件 该界面只会被渲染一次 显示时渲染】
        //记录 当前界面是否已经加载过一次 用来 选中 该界面 子组件赋值 【子组件在为渲染时 去设置子组件值是无法操作的】
        this.IsLoadShooingAdd = true;
        window['IsLoadShooingAdd'] = true;
        //console.log("window['IsLoadShooingAdd'] " +window['IsLoadShooingAdd'])
      },
    methods: {//函数定义

      //关闭
      Colese(){
        this.$emit("SetObj","Setshow_ds_Register",false);// 关闭界面
      },


      //详情加载
      loadFindData(){

        let map ={};
        map.EIY_ID = this.form.EIY_ID;
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        FindInfo(Pwd_Str).then(response => {
          let jsonobj =  JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj)
          var Rmap = jsonobj.Data.EIY_Map;
          var SAN_Map = JSON.parse(JSON.stringify(this.form));
          SAN_Map.EIY_ID = Rmap.EIY_ID;
          SAN_Map.SAN_Time = Rmap.SAN_Time;
          SAN_Map.SAN_CoName = Rmap.SAN_CoName;
          SAN_Map.SAN_Sender_Name = Rmap.SAN_Sender_Name;
          SAN_Map.SAN_Recipient_Name = Rmap.SAN_Recipient_Name;
          SAN_Map.SAN_Recipient_Address = Rmap.SAN_Recipient_Address;
          SAN_Map.EIY_Ship_Time = Rmap.EIY_Ship_Time;
          SAN_Map.EIY_ShiptyID = ''+Rmap.EIY_ShiptyID;
          SAN_Map.EIY_FpayType = ''+Rmap.EIY_FpayType;
          SAN_Map.EIY_Tracking_Number = Rmap.EIY_Tracking_Number;
          SAN_Map.SAN_Recipient_Tel = Rmap.SAN_Recipient_Tel;
          SAN_Map.EIY_Time = Rmap.EIY_Time;
          SAN_Map.EIY_Signing_Status = ''+Rmap.EIY_Signing_Status;
          SAN_Map.EIY_Evaluation_Status = ''+Rmap.EIY_Evaluation_Status;


          SAN_Map.EIY_Express_Delivery = Rmap.EIY_Express_Delivery;
            // SAN_Map.EIY_Express_Delivery = tools.getkeyValue(this.CourierCompanyOptions,Rmap.EIY_Express_Delivery,"EDY_ID","EDY_Name");
          SAN_Map.EIY_Delivery_Person = Rmap.EIY_Delivery_Person;
          SAN_Map.EIY_Remarks = Rmap.EIY_Remarks;
          this.changeEIY_ShiptyID(SAN_Map.EIY_ShiptyID); //执行 一次 发货方式 切换  显示对应数据

          this.$emit("SetObj","Setform",SAN_Map);//重置 form 数据

          this.CommodityList = jsonobj.Data.EIDS_arr;


        });


      },


      //set 客户信息 查询参数
      SetSel(Map){
        this.Sel = Map;
        //console.log(this.Sel)
      },


      //编辑 发货申请 信息 数据载入
      SetShipmentApplication(){
        //清空 原有数据
        this.CommodityList = [];
        this.EditBool = true;//当前打开为 编辑模式
        this.$emit("SetObj","SetExecute",true);//已加载 载入合同

        this.loadFindData() //详情加载
      },








      //新增发票发货 按钮点击
      LoadSAIE(){
        this.Invoicetitle = '新增 发票发货';//发票发货 标题
        this.Invoice_show = true;//发票发货 显示
        this.addInvoiceBtn = true;//新增按钮 发票发货 显示
        this.editInvoiceBtn =  true,//关闭按钮 发票发货 显示


          //发票发货 form
        this.Invoiceform = {
          SAIE_Billing_Company:'',
          SAIE_Quantity:'1'
        };
      },
      //新增发票发货
      addInvoicePush(){
        let _this = this;
        if (tools.VerificationsText(_this, _this.Invoiceform.SAIE_Billing_Company, "请填写开票公司！") == true &&
          tools.VerificationsText(_this, _this.Invoiceform.SAIE_Quantity, "请选择开票数量！") == true) {
          let map = JSON.parse(JSON.stringify(this.Invoiceform));
          this.InvoiceList.push(map);
          this.msgSuccess("已添加至界面缓存，需点击确认保存！");
        }
      },

      //删除 发票发货
      DelInvoice(index, row) {
        if (row.SAIE_ID != null && row.SAIE_ID != "" ) {
          this.InvoiceList_delArr.push(row.SAIE_ID);
        }
        this.InvoiceList.splice(index, 1);
        this.msgSuccess("已删除界面缓存，需点击确认保存！");
      },

      //新增 其他发货 按钮点击
      LoadSAOR(){
        this.othertitle = '新增 发票发货';//发票发货 标题
        this.other_show = true;//发票发货 显示
        this.addotherBtn = true;//新增按钮 发票发货 显示
        this.editotherBtn =  true,//关闭按钮 发票发货 显示
          //发票发货 form
          this.otherform = {
            SAOR_Name:'',
            SAOR_ModelAndNumber:'',
            SAOR_Unit:'',
            SAOR_Quantity:'1',
          };
      },
      //新增 其他发货
      addotherPush(){
        let _this = this;
        if (tools.VerificationsText(_this, _this.otherform.SAOR_Name, "请填写名称！") == true &&
          tools.VerificationsText(_this, _this.otherform.SAOR_Unit, "请填写单位！") == true &&
          tools.VerificationsText(_this, _this.otherform.SAOR_Quantity, "请选择数量！") == true) {
          let map = JSON.parse(JSON.stringify(this.otherform));
          this.otherList.push(map);
          this.msgSuccess("已添加至界面缓存，需点击确认保存！");
        }
      },

      //删除 其他发货
      DelOther(index, row) {
        if (row.SAOR_ID != null && row.SAOR_ID != "" ) {
          this.otherList_delArr.push(row.SAOR_ID);
        }
        this.otherList.splice(index, 1);
        this.msgSuccess("已删除界面缓存，需点击确认保存！");
      },





      //加载 发货信息
      LoadContractShippingInformation(){
        let Pmap = {};
        Pmap.type = 'CT';
        Pmap.ODY_Contract_ID = this.form.SAFL_ODYContractID;
        Pmap.CtID = Pmap.ODY_Contract_ID;
        //console.log(Pmap)
        this.getQuantitySd(Pmap);//加载商品申请发货数量
      },


      //格式化 发货数量
      setSAOR_Quantity(row){
        if(!tools.Is_null(row.EIDS_Quantity)){
          row.EIDS_Quantity = 1;
        }
      },



      //获取 【当前查询用户】未完成的销售合同ID
      findUndoneContract(){
        //选中 客户再查询
        if(tools.Is_null(this.form.SAN_CoID)){
          let map ={};
          map.CoID = this.form.SAN_CoID;
          let Pwd_Str = tools.encrypt(JSON.stringify(map));
          getUndoneContract(Pwd_Str).then(response => {
            let jsonobj =  JSON.parse(tools.Decrypt(response));
            //console.log(jsonobj)
            this.UndoneCodeOption = jsonobj.Data;

            if(this.UndoneCodeOption!=null &&  this.UndoneCodeOption.length>0){
              this.form.SAFL_ODYContractID = this.UndoneCodeOption[0].ODY_Contract_ID;//选中 第一个
              //this.LoadContractShippingInformation();//加载 发货信息
            }else{
              tools.open(this, "当前客户，没有待发货销售合同！");
            }
          });
        }else{
          tools.open(this, "请选择 先根据检索条件查询出 客户并选择！")
        }
      },

      //切换 销售合同订单
      changSAFL_ODYContractID(){
        //this.LoadContractShippingInformation();//加载 发货信息
      },





      //选中 当前登录用户
      SetAdminOption() {
        if (this.SalesOption != null && this.SalesOption.length > 0) {
          this.AdminOption = [];
          //默认选择第一个
          this.form.c_party_b_phone = this.SalesOption[0].phonenumber;
          this.form.c_party_b_id = this.SalesOption[0].user_id;
          let username = tools.getCookie("username");
          for (let i = 0; i < this.SalesOption.length; i++) {
            let Obj = this.SalesOption[i];
            this.AdminOption.push(Obj);
            window["SalesOptionPhonenumber_" + Obj.user_id] = Obj.phonenumber;
            //选中当前登录用户信息
            //console.log(username == Obj.user_name);
            if (Obj.user_name == username) {
              this.form.c_party_b_phone = Obj.phonenumber;
              this.form.c_party_b_id = Obj.user_id;
              this.form.c_userId = Obj.user_id;
            }
          }
        }
      },
      rowClassName({row, rowIndex}) {
        //把每一行的索引放进row
        row.index = rowIndex;
      },



      //删除 合同商品
      DelformalDetailsArr(index, row) {
        if (row.SAFDS_ID != null && row.SAFDS_ID != "" ) {
          this.formalDetailsArr_delArr.push(row.SAFDS_ID);
        }
        this.formalDetailsArr.splice(index, 1);
        this.msgSuccess("已删除界面缓存，需点击确认保存！");
      },

      //删除 商品 信息
      DelAccount(index, row) {
        if (row.ASOY_ID != null && row.ASOY_ID != "" ) {
          this.CommodityList_delArr.push(row.ASOY_ID);
        }
        this.CommodityList.splice(index, 1);
        this.msgSuccess("已删除界面缓存，需点击确认保存！");
      },







      //选择商品
      LoadCommodity(){
        //清空选择
        this.FindCommodity();
      },

      //查询商品简称
      FindCommodity(){
        //console.log(this.commodity)
        let Pwd_Str = tools.encrypt(JSON.stringify(this.commodity));
        Commodity(Pwd_Str).then(response => {
          let jsonobj =  JSON.parse(tools.Decrypt(response));
          this.cities = JSON.parse(JSON.stringify(jsonobj.Data));
          this.cityOptions = JSON.parse(JSON.stringify(jsonobj.Data));
          this.innerDrawer = true;
        });

      },




      //发货方式 切换
      changeEIY_ShiptyID(EIY_ShiptyID){
         EIY_ShiptyID = EIY_ShiptyID!=null?EIY_ShiptyID:this.form.EIY_ShiptyID;
        if(EIY_ShiptyID=='1' || EIY_ShiptyID=='2'){
          this.EIY_FpayType_show = true;
          this.EIY_Remarks_show = false;
          this.EIY_Delivery_Person_show = false;
        }else if(EIY_ShiptyID=='3'){
          this.EIY_FpayType_show = false;
          this.EIY_Remarks_show = false;
          this.EIY_Delivery_Person_show = true;
        }else if(EIY_ShiptyID=='4' || EIY_ShiptyID=='5'){
          this.EIY_FpayType_show = false;
          this.EIY_Remarks_show = true;
          this.EIY_Delivery_Person_show = false;
        }
      },






      // 提交 编辑 通用验证
      SubUniversalVerification(){
        let _this = this;
        if (tools.VerificationsText(_this, _this.EIY_Ship_Time, "请选择 发货日期！") == true) {
          if(tools.DateBiJiao(_this.EIY_Ship_Time,tools.gitData())){
            this.ShiptyIDVerification();//发货方式验证
          }else{
            tools.open(_this, "发货时间不能大于当前日期！")
          }
        }
      },




      //发货方式验证
      ShiptyIDVerification(){
        let _this = this;
        let EIY_ShiptyID = this.form.EIY_ShiptyID;
        if(EIY_ShiptyID=='1' || EIY_ShiptyID=='2'){
          if (
            tools.VerificationsText(_this, _this.form.EIY_FpayType, "请选择 运费方式！") == true &&
            tools.VerificationsText(_this, _this.form.SAN_Express_Delivery, "请选择 快递公司！") == true) {
            this.ShipmentDataVerification();//发货数据验证
          }
        }else if(EIY_ShiptyID=='3'){
          if (
            tools.VerificationsText(_this, _this.form.EIY_Delivery_Person, "请填写 送货人！") == true) {
            this.ShipmentDataVerification();//发货数据验证
          }
        }else if(EIY_ShiptyID=='4' || EIY_ShiptyID=='5'){
          if (
            tools.VerificationsText(_this, _this.form.EIY_Remarks, "请填写 备注！") == true) {
            this.ShipmentDataVerification();//发货数据验证
          }
        }
      },

      //发货数据验证
      ShipmentDataVerification(){
          //过滤申请发货 数量 为 0 的 数据 做删除
          if(this.CommodityList.length>0){
            let CommodityList = [];
            for (let i = 0; i < this.CommodityList.length; i++) {
              let obj = this.CommodityList[i];
              if(obj.EIDS_Quantity>0){
                CommodityList.push(obj);
              }
            }
            this.CommodityList = CommodityList;
          }
          if(this.CommodityList.length>0){

            let map = {};
            let SAN_Map = this.form;

            //数据赋值
            // 获取 SAN_CoName 客户名称  SAN_Sender_Name 发货人姓名 SAN_Recipient_Name 收件人
            this.form.SAN_CoName = tools.getkeyValue(this.CustomerOption, this.form.SAN_CoID, "id", "c_name");
            this.form.SAN_Recipient_Name = tools.getkeyValue(this.PeopleOption, this.form.c_party_a_id, "id", "NAME");


            var ASOY_arr = [];//普通发货信息
            var SAIE_arr = [];//发票发货信息
            var SAOR_arr = [];//其他发货信息
            var SAFL_Map = {};//发货申请正式合同发货信息
            var SAFDS_arr= [];//发货申请正式合同发货信息详情


            let EIDS_arr = [];// 快递查询信息详情
            let up_ID_arr = [];//发货的商品 数据 id 信息
            //获取 快递查询信息详情
            for (let i = 0; i < this.CommodityList.length; i++) {
              let o_map = this.CommodityList[i];
              if(tools.Is_null(o_map.Up_ID)==true){
                up_ID_arr.push(o_map);
              }
              EIDS_arr.push(this.CommodityList[i]);
            }
            //console.log(up_ID_arr);
            // console.log(EIDS_arr);
            //console.log(this.CommodityList);
            let Owe_Quantity_Sum = "0";
            let Sent_Quantity_Sum = 0;
            let Imp_data_length = 0;//计数欠发数量大于等于0的行数
            let count_sum = 0;//计算发货申请 总行数
            //根据 选择的 发货 方式获取 对应的 数据信息
            for (let i = 0; i < up_ID_arr.length; i++) {
              let o = up_ID_arr[i];
              //循环获取本应该发货数量
              for (let j = 0; j < this.formalDetailsArr.length; j++) {
                let F_map = this.formalDetailsArr[j];
                let Imp_ID = F_map.Imp_ID;
                let type = F_map.type;
                let name = F_map.Name;
                let Sent_Quantity = F_map.Sent_Quantity;
                let Owe_Quantity = F_map.Owe_Quantity;


                if(this.is_same(type,o.EIDS_Shipping_Type,name,o.EIDS_Name)){
                  switch (type) {
                    case '合同发货':
                      //合同发货 发货
                      //合同发货 发货详情
                      var o_map = {};

                      o_map.SAFDS_ID  = tools.not_null_Get_value(Imp_ID);//ID
                      o_map.SAFDS_Sent_Quantity  = Sent_Quantity;//发货数量
                      //发货数量 = 当前发货数量 + 快递数量
                      o_map.SAFDS_Sent_Quantity = tools.accAdd(o_map.SAFDS_Sent_Quantity,o.EIDS_Quantity);
                      o_map.SAFDS_Owe_Quantity  = Owe_Quantity;//欠发数量

                      //如果欠发数量大于0累加	 发货申请 总行数
                      if(Number(o_map.SAFDS_Owe_Quantity)>0){
                        count_sum=tools.accAdd(count_sum,1);
                      }

                      //欠发数量 = 当前欠发数量 - 快递数量
                      o_map.SAFDS_Owe_Quantity = tools.numSub(o_map.SAFDS_Owe_Quantity,o.EIDS_Quantity);
                      Sent_Quantity_Sum =tools.accAdd(Sent_Quantity_Sum,o_map.SAFDS_Sent_Quantity);//累加发货数量
                      SAFDS_arr.push(o_map);
                      Owe_Quantity_Sum =tools.accAdd(Owe_Quantity_Sum,o_map.SAFDS_Owe_Quantity);//累加欠发数量
                      break;
                    case '普通发货':
                      //普通发货信息
                      var o_map = {};

                      o_map.ASOY_ID = tools.not_null_Get_value(Imp_ID);//ID
                      o_map.ASOY_Sent_Quantity  = Sent_Quantity;//发货数量
                      //发货数量 = 当前发货数量 + 快递数量
                      o_map.ASOY_Sent_Quantity = tools.accAdd(o_map.ASOY_Sent_Quantity,o.EIDS_Quantity);
                      o_map.ASOY_Owe_Quantity  = Owe_Quantity;//欠发数量
                      //如果欠发数量大于0累加	 发货申请 总行数
                      if(Number(o_map.ASOY_Owe_Quantity)>0){
                        count_sum=tools.accAdd(count_sum,1);
                      }
                      //欠发数量 = 当前欠发数量 - 快递数量
                      o_map.ASOY_Owe_Quantity = tools.numSub(o_map.ASOY_Owe_Quantity,o.EIDS_Quantity);
                      Sent_Quantity_Sum =tools.accAdd(Sent_Quantity_Sum,o_map.ASOY_Sent_Quantity);//累加发货数量
                      ASOY_arr.push(o_map);
                      Owe_Quantity_Sum =tools.accAdd(Owe_Quantity_Sum,o_map.ASOY_Owe_Quantity);//累加欠发数量

                      break;
                    case '发票发货':
                      //发票发货信息
                      var o_map = {};


                      o_map.SAIE_ID = tools.not_null_Get_value(Imp_ID);//ID
                      o_map.SAIE_Sent_Quantity  = Sent_Quantity;//发货数量
                      //发货数量 = 当前发货数量 + 快递数量
                      o_map.SAIE_Sent_Quantity = tools.accAdd(o_map.SAIE_Sent_Quantity,o.EIDS_Quantity);
                      o_map.SAIE_Owe_Quantity  = Owe_Quantity;//欠发数量

                      //如果欠发数量大于0累加	 发货申请 总行数
                      if(Number(o_map.SAIE_Owe_Quantity)>0){
                        count_sum=tools.accAdd(count_sum,1);
                      }
                      //欠发数量 = 当前欠发数量 - 快递数量
                      o_map.SAIE_Owe_Quantity = tools.numSub(o_map.SAIE_Owe_Quantity,o.EIDS_Quantity);
                      Sent_Quantity_Sum =tools.accAdd(Sent_Quantity_Sum,o_map.SAIE_Sent_Quantity);//累加发货数量
                      SAIE_arr.push(o_map);
                      Owe_Quantity_Sum =tools.accAdd(Owe_Quantity_Sum,o_map.SAIE_Owe_Quantity);//累加欠发数量
                      break;
                    case '其他发货':
                      //其他发货信息
                      var o_map = {};

                      o_map.SAOR_ID = tools.not_null_Get_value(Imp_ID);//ID
                      o_map.SAOR_Sent_Quantity  = Sent_Quantity;//发货数量
                      //发货数量 = 当前发货数量 + 快递数量
                      o_map.SAOR_Sent_Quantity = tools.accAdd(o_map.SAOR_Sent_Quantity,o.EIDS_Quantity);
                      o_map.SAOR_Owe_Quantity  = Owe_Quantity;//欠发数量

                      //如果欠发数量大于0累加	 发货申请 总行数
                      if(Number(o_map.SAOR_Owe_Quantity)>0){
                        count_sum=tools.accAdd(count_sum,1);
                      }
                      //欠发数量 = 当前欠发数量 - 快递数量
                      o_map.SAOR_Owe_Quantity = tools.numSub(o_map.SAOR_Owe_Quantity,o.EIDS_Quantity);
                      Sent_Quantity_Sum =tools.accAdd(Sent_Quantity_Sum,o_map.SAOR_Sent_Quantity);//累加发货数量
                      SAOR_arr.push(o_map);
                      Owe_Quantity_Sum =tools.accAdd(Owe_Quantity_Sum,o_map.SAOR_Owe_Quantity);//累加欠发数量



                      break;
                    default:
                      break;
                  }
                }









              }
            }



            for (let k = 0; k < this.formalDetailsArr.length; k++) {
                let F_map =  this.formalDetailsArr[k];
                let Owe_Quantity = F_map.Owe_Quantity;
                if(Number(Owe_Quantity)>0){
                  Imp_data_length = tools.accAdd(1,Imp_data_length);
                }
            }

            // console.log('Imp_data_length -- '+Imp_data_length+' count_sum   -  '+count_sum )
            // console.log('Owe_Quantity_Sum -- '+Owe_Quantity_Sum+' Sent_Quantity_Sum   -  '+Sent_Quantity_Sum )

            SAN_Map.SAN_Delivery_Status = Imp_data_length==count_sum && Owe_Quantity_Sum<=0?3:Sent_Quantity_Sum>0?2:1; // 发货状态

            //提交参数打包
            map.SAN_ID = SAN_Map.SAN_ID;
            SAN_Map.EIY_ShiptyID = SAN_Map.EIY_ShiptyID;// 发货方式

            SAN_Map.EIY_Ship_Time = this.EIY_Ship_Time;//发货日期
            map.EIY_Map = SAN_Map;// 发快递查询 信息


            map.SAFL_Map = {"SAFL_ODYContractID":this.form.SAFL_ODYContractID};
            map.ASOY_arr = ASOY_arr;//普通发货信息
            map.SAIE_arr = SAIE_arr;//发票发货信息
            map.SAOR_arr = SAOR_arr;//其他发货信息
            map.SAFDS_arr = SAFDS_arr;//发货申请正式合同发货信息详情
            map.EIDS_arr = EIDS_arr;//快递查询信息详情
            map.SAN_Map = {'SAN_Delivery_Status':SAN_Map.SAN_Delivery_Status,'SAN_ID':SAN_Map.SAN_ID};// 发快递查询 信息


            this.SubUpd(map);

          }else{
            tools.open(this, "您还未填写需要申请发货的信息！！！");
          }
      },

      //编辑
      Edie() {
        this.SubUniversalVerification(); // 提交 编辑 通用验证
      },

      //判断传入快递数据与申请数据是否一致
      is_same(type,type_1,name,name_1){
        var type_bool =false,name_bool =false;
        type_bool = type==type_1?true:false;
        name_bool = name==name_1?true:false;
        return (type_bool==true && name_bool==true?true:false);
      },


    }
  };
</script>
